package jiketang11;

import java.awt.*;

interface Shape {
    public double area();

    public double circumference();
}

class Circle implements Shape {
    private double radius; // 半径
    private Point center; // 圆心位置

    public Circle() {
        this.radius = 0;
        this.center = new Point(0, 0);
    }

    public Circle(double radius) {
        this.center = new Point(0, 0);
        this.radius = radius;
    }

    public Circle(double radius, Point center) {
        this.radius = radius;
        this.center = center;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setCenter(Point center){
        this.center=center;
    }
    public Point getCenter() {
        return center;
    }
    public double area() {
        return 3.14 * radius * radius;
    }

    public double circumference() {
        return 2 * 3.14 * radius;
    }
}

class Square implements Shape {
    private double length;
    private double width;
    private Point topAndCorner;

    public void setlength(double length) {
        this.length = length;
    }

    public void setwidth(double width) {
        this.width = width;
    }

    public void settopAndCorner(Point topAndCorner){
        this.topAndCorner=topAndCorner;
    }
    public double getLength() {
        return length;
    }
    public double getWidth() {
        return width;
    }
    public Point getTopAndCorner() {
        return topAndCorner;
    }
    public Square() {
        this.topAndCorner = new Point(0, 0);
        this.length = 1;
        this.width = 1;
    }

    public Square(double length, double width) {
        this.length = length;
        this.topAndCorner = new Point(0, 0);

        this.width = width;
    }

    public Square(double length, double width, Point topAndCorner) {
        this.length = length;
        this.width = width;
        this.topAndCorner = topAndCorner;
    }

    public double area() {
        return length * width;
    }

    public double circumference() {
        return 2 * (length + width);
    }
}

public class jiketang11 {
    //既可以输出圆又可以输出矩形
     public static void printShapeInfo(Shape shape) {
        System.out.printf("周长:%.2f, 面积:%.2f, ", 
                         shape.circumference(), shape.area());
        
        if (shape instanceof Circle) {
            Circle circle = (Circle) shape;
            Point center = circle.getCenter();
            System.out.printf("位置: 圆心(%d, %d)\n", center.x, center.y);
        } else if (shape instanceof Square) {
            Square square = (Square) shape;
            Point corner = square.getTopAndCorner();
            System.out.printf("位置:(%d, %d)\n", corner.x, corner.y);
        }
    }
    public static void main(String[] args) {
        Circle circle1 = new Circle();
        Circle circle2 = new Circle(2);
        Circle circle3 = new Circle(3, new Point(1, 2));
        // circle.setRadius(6);
        Point center1 = circle1.getCenter();
        printShapeInfo(circle1);
        printShapeInfo(circle2);
        printShapeInfo(circle3);
        
        System.out.println("使用setter和getter后:\n");
        circle1.setRadius(3);
        circle1.setCenter(new Point(1,2));
        center1=circle1.getCenter();
        System.out.printf("周长:%.2f 面积:%.2f 圆心:%d %d\n", circle1.circumference(), circle1.area(),center1.x,center1.y);
        printShapeInfo(circle1);        
        
        System.out.println("矩形:");
        Square square1 = new Square();
        Square square2 = new Square(2, 2);
        Square square3 = new Square(2, 3, new Point(1, 1));
        Point topAndCorner1=square1.getTopAndCorner();
        printShapeInfo(square1); 
        printShapeInfo(square2);
        printShapeInfo(square3);
      
        System.out.println("setter和getter:");
        square1.setlength(3);
        square1.setwidth(4);
        square1.settopAndCorner(new Point(10,10));
        topAndCorner1=square1.getTopAndCorner();
        System.out.printf("Square1:周长:%.2f 面积:%.2f topAndCorner:(%d,%d)\n", square1.circumference(), square1.area(),topAndCorner1.x,topAndCorner1.y);// 在main方法中使用String.format保留2位小数

    }
}
